import configparser
import pathlib
import os
import sys
import easygui
root=pathlib.Path(os.path.dirname(os.path.realpath(sys.argv[0])))
root=pathlib.Path(os.path.dirname(os.path.realpath(__file__)))
dx=['零','一','二','三','四','五','六','七','八','九','十','十一','十二']

def readconfig():
    conf = configparser.ConfigParser(allow_no_value=True)
    try:
        conf.read(str(root/"config.ini"), encoding="utf-8")
    except :
        try :
            print("config read for GBK")
            conf.read(str(root/"config.ini"), encoding="GBK")
        except:
            easygui.msgbox("配置文件读取错误")
    return conf

localconfig = configparser.ConfigParser(allow_no_value=True)
try:
    localconfig.read(str(root/"configLocal.ini"), encoding="utf-8")
except :
    try :
        print("config read for GBK")
        localconfig.read(str(root/"configLocal.ini"), encoding="GBK")
    except:
        easygui.msgbox("配置文件读取错误")
try:
    localconfig.add_section('local')
except:
    pass
localconfig.write(open(str(root/"configLocal.ini"), "w"))
conf=readconfig()
alias={}
alias_={}
for i in conf.items("alias") :
    alias[i[0]]=i[1]
    alias_[i[1]]=i[0]

examAlias={}
examAlias_={}
for i in conf.items("examAlias") :
    examAlias[i[0]]=i[1]
    examAlias_[i[1]]=i[0]

def getClassNo(ali):
    global alias_
    if(ali[-1]=="班"):
        ali=ali[:-1]
    if(ali in alias_):
        return alias_[ali]
    else:
        return ali

def getAlias(ali):
    global alias
    if(ali in alias):
        return alias[ali]
    else:
        return ali
def getExamAlias(ali):
    global examAlias
    if(ali in examAlias):
        return examAlias[ali]
    else:
        return ali
def getExamNo(ali):
    global examAlias_
    if(ali in examAlias_):
        return examAlias_[ali]
    else:
        return ali